// 此文件用于编辑模式模版配置侧配置
import _ from 'lodash';
import {
  tabList,
  tabList2,
  colorList8,
  styleimg8,
  colorList10,
  styleimg10,
  colorList9,
  styleimg9,
  colorList4,
  colorList5,
  colorList6,
  styleimg4,
  styleimg5,
  colorList,
  colorInfo,
  fontSizeList,
  fontFamilyList,
  styleimg,
  colorList11,
  moduleType,
  SubunitList,
  moduleType4,
  SubunitList4,
  colorList15,
  SubunitList15,
  colorList13,
  SubunitList13,
  moduleType15,
  moduleType13,
  styleimg13,
  SubunitList17,
  colorList17,
  StyleImage17,
  SubunitList17List,
  SubunitExhibits,
} from '@/pages/templatePage/data';
import { moduleType14 } from '@/pages/templatePage/template14/color';
import { SubunitList16List } from '@/pages/templatePage/template16/color';
import { SubunitList19List } from '@/pages/templatePage/template19/color';
import { moduleType18 } from '@/pages/templatePage/painting/data';
import { colorList16, template16Styleimg, SubunitList16 } from '@/pages/templatePage/template16/color';
import { colorList19, template19Styleimg, SubunitList19 } from '@/pages/templatePage/template19/color';
import { template14ColorList, template14Styleimg, moduleImg } from '@/pages/templatePage/template14/color';
import { template18ColorList, template18Styleimg, template18ModuleImg } from '@/pages/templatePage/painting/data';
const getGlobalTabList = (templateId?: number | string) => {
  //设置全局设置中各tab的显示或隐藏
  let arr = {
    colorShow: true, //颜色展示
    sizeShow: false, //字体选择展示
    styleShow: true, //风格样式
  };
  return arr;
};
const getStyleRandom = (array: any, type: number, isInit: boolean) => {
  //array 当前可选所有样式列表
  //type 当前选中的type
  //isInit 是否是第一次初始化
  //获取随机的下标
  let returnId = 0;
  if (isInit) {
    let index = Math.floor(Math.random() * array.length); //获取随机下标
    returnId = array[index].id;
  } else {
    let isExistence = array.findIndex((element) => {
      return element.id === type;
    });

    if (isExistence !== -1) {
      returnId = type;
    } else {
      let index = Math.floor(Math.random() * array.length); //获取随机下标
      returnId = array[index].id;
    }
  }
  // console.log(returnId);
  return returnId;
};
const getRandomModuleList = (data, templateId, isInit) => {
  //data原数据 templateId当前模版id
  //初始化单元逻辑

  let clonedObject = _.cloneDeep(data);
  clonedObject.forEach((element) => {
    if (templateId == 395740859879493) {
      //模版一组件切换逻辑
      if (element.children.length > 0) {
        switch (element.children.length) {
          case 1:
            element.type = 12;
            break;
          case 2:
            element.type = getStyleRandom(moduleType.Subunit[1], element.type, isInit);
            break;
          case 3:
            element.type = getStyleRandom(moduleType.Subunit[2], element.type, isInit);
            break;
          case 4:
            element.type = getStyleRandom(moduleType.Subunit[3], element.type, isInit);
            break;
          case 5:
            element.type = getStyleRandom(moduleType.Subunit[4], element.type, isInit);
            break;
          case 6:
            element.type = getStyleRandom(moduleType.Subunit[5], element.type, isInit);
            break;
          default:
            element.type = getStyleRandom(moduleType.Subunit[6], element.type, isInit);
            break;
        }
      } else if (element.children.length === 0 && element.showpieceTotal > 0) {
        element.type = getStyleRandom(moduleType.exhihits, element.type, isInit);
      } else {
        element.type = getStyleRandom(moduleType.preface, element.type, isInit);
      }
    }
    if (templateId == 410276336631877) {
      //模版四组件切换逻辑
      if (element.children.length > 2) {
        element.type = getStyleRandom(moduleType4.Subunit[2], element.type, isInit);
      } else if (element.children.length == 2) {
        element.type = getStyleRandom(moduleType4.Subunit[1], element.type, isInit);
      } else {
        element.type = getStyleRandom(moduleType4.Subunit[0], element.type, isInit);
      }
    }
    if (templateId == 2013) {
      //模版13组件切换逻辑
      if (element.showpieceTotal > 0 && element.children.length === 0) {
        if (element.type > 3 && element.type < 8) {
          element.type = element.type;
        } else {
          element.type = getStyleRandom(moduleType13.Subunit[1], element.type, isInit);
        }
        //console.log(element);
      } else if (element.children.length === 0 && element.showpieceTotal === 0) {
        element.type = getStyleRandom(moduleType13.Subunit[0], element.type, isInit);
      } else {
        element.type = getStyleRandom(moduleType13.Subunit[2], element.type, isInit);
      }
    }
    if (templateId == 503306628902981) {
      //模版14组件切换逻辑
      if (element.children.length > 0) {
        element.type = getStyleRandom(moduleType14.Subunit[2], element.type, isInit);
      } else if (element.showpieceTotal > 0) {
        element.type = getStyleRandom(moduleType14.Subunit[1], element.type, isInit);
      } else {
        element.type = getStyleRandom(moduleType14.Subunit[0], element.type, isInit);
      }
    }
    if (templateId == 2001) {
      //模版15组件切换逻辑
      if (element.children.length == 0) {
        element.type = getStyleRandom(moduleType15.Subunit[0], element.type, isInit);
      } else if (element.children.length == 1) {
        element.type = getStyleRandom(moduleType15.Subunit[1], element.type, isInit);
      } else if (element.children.length == 2) {
        element.type = getStyleRandom(moduleType15.Subunit[2], element.type, isInit);
      } else {
        element.type = getStyleRandom(moduleType15.Subunit[3], element.type, isInit);
      }
    }
    if (templateId == 505022027386949) {
      //模版16组件切换逻辑

      if (element.children.length == 0 && element.showpieceTotal == 0) {
        element.type = getStyleRandom(SubunitList16List.Subunit[0], element.type, isInit);
      } else if (element.children.length == 0) {
        element.type = getStyleRandom(SubunitList16List.Subunit[1], element.type, isInit);
      } else if (element.children.length > 0) {
        element.type = getStyleRandom(SubunitList16List.Subunit[2], element.type, isInit);
      }
    }
    if (templateId == 1717) {
      //模版17组件切换逻辑
      if (element.children.length == 0 && element.showpieceTotal == 0) {
        element.type = getStyleRandom(SubunitList17.Subunit[0], element.type, isInit);
      } else if (element.children.length == 0) {
        if (element.remarks?.length > 0 || element.value) {
          element.type = getStyleRandom(SubunitList17.Subunit[1], element.type, isInit);
        } else element.type = getStyleRandom(SubunitExhibits[0], element.type, isInit);
      } else if (element.children.length > 0) {
        element.type = getStyleRandom(SubunitList17.Subunit[2], element.type, isInit);
      }
    }
    if (templateId == 507481625702469) {
      //模版18组件切换逻辑
      if (element.children.length == 0) {
        element.type = getStyleRandom(moduleType18.Subunit[0], element.type, isInit);
      } else if (element.children.length > 0) {
        element.type = getStyleRandom(moduleType18.Subunit[1], element.type, isInit);
      }
    }
    if (templateId == 529130430058565) {
      //模版19切换逻辑

      if (element.children.length == 0) {
        // 一级单元
        element.type = getStyleRandom(SubunitList19List.Subunit[0], element.type, isInit);
      } else if (element.children.length > 0) {
        // 二级单元
        element.type = getStyleRandom(SubunitList19List.Subunit[1], element.type, isInit);
      }
    }
  });

  // console.log(clonedObject, '生成的当前参数');
  return clonedObject;
};
const getLogoTabList = (templateId?: number | string) => {
  //设置logo设置中各tab的显示或隐藏
  let arr = {
    LogoShow: true, //logo上传功能
    banner: true, //轮播图功能
    wapBanner: true, //移动端轮播图上传
  };
  return arr;
};
const getEditRightTab = (templateId: number | string) => {
  //配置右侧侧边栏配置图表
  if (
    templateId == 395741054230597 ||
    templateId == 410276243316805 ||
    templateId == 666 ||
    templateId == 123456789 ||
    templateId == 99999 ||
    templateId == 1010 ||
    templateId == 888 ||
    templateId == 1997
  ) {
    return tabList2; //不包含首页样式
  } else {
    return tabList;
  }
};
const getGlobalColor = (templateId: number | string) => {
  let setting = {
    templateColorList: [],
    templateStyleimg: [],
  };
  console.log(templateId, '--------------templateId---------------------');
  //获取全局颜色以及图标样式表
  switch (templateId) {
    case 410276336631877:
      setting.templateColorList = colorList4;
      setting.templateStyleimg = styleimg4;
      break;
    case 666:
      setting.templateColorList = colorList6;
      break;
    case 1997:
      setting.templateColorList = colorList5;
      setting.templateStyleimg = styleimg5;
      break;
    case 99999:
      setting.templateColorList = colorList9;
      setting.templateStyleimg = styleimg9;
      break;
    case 888:
      setting.templateColorList = colorList8;
      setting.templateStyleimg = styleimg8;
      break;
    case 1010:
      setting.templateColorList = colorList10;
      setting.templateStyleimg = styleimg10;
      break;
    case 123456789:
      setting.templateColorList = colorList11;
      setting.templateStyleimg = [];
      break;
    case 2001:
      setting.templateColorList = colorList15;
      setting.templateStyleimg = [];
      break;
    case 2013:
      setting.templateColorList = colorList13;
      setting.templateStyleimg = styleimg13;
      break;
    case 503306628902981:
      setting.templateColorList = template14ColorList;
      setting.templateStyleimg = template14Styleimg;
      break;
    case 505022027386949:
      setting.templateColorList = colorList16;
      setting.templateStyleimg = template16Styleimg;
      break;
    case 507481625702469:
      setting.templateColorList = template18ColorList;
      setting.templateStyleimg = template18Styleimg;
      break;
    case 529130430058565:
      setting.templateColorList = colorList19;
      setting.templateStyleimg = template19Styleimg;
      break;
    case 1717:
      setting.templateColorList = colorList17;
      setting.templateStyleimg = StyleImage17;
      break;
    default:
      setting.templateColorList = colorList;
      setting.templateStyleimg = styleimg;
      break;
  }
  return setting;
};
//获取单元样式配置列表
const getUnitStyle = (templateId: number | string) => {
  let unitList = [];

  switch (templateId) {
    case 410276336631877:
      unitList = SubunitList4;
      break;
    case 503306628902981:
      unitList = moduleImg;
      break;

    case 505022027386949:
      unitList = SubunitList16;
      break;
    case 529130430058565:
      unitList = SubunitList19;
      break;
    case 2001:
      unitList = SubunitList15;
      break;
    case 2013:
      unitList = SubunitList13;
      break;
    case 507481625702469:
      unitList = template18ModuleImg;
      break;
    case 1717: // 组件设置中的选中封面
      unitList = SubunitList17List;
      break;
    case 395740859879493:
      unitList = SubunitList;
      break;

    //default 要为空数组，用来判断是否有高级组件
  }
  return unitList;
};
const getChildType = (arr) => {
  let type = false;
  arr.forEach((element) => {
    if (element.children.length > 0) {
      type = true;
    }
  });
  return type;
};
export const getUnitStyleType = (templateId: number | string, e: any, index: number) => {
  //模版单元选择逻辑剥离
  switch (templateId) {
    case 410276336631877:
      if (e.children.length == 0 || e.children.length == 1) {
        return moduleType4.Subunit[0];
      } else if (e.children.length > 3) {
        if (e.children.length == 1) {
          return moduleType4.Subunit[1];
        } else {
          return moduleType4.Subunit[2];
        }
      } else {
        return moduleType4.Subunit[e.children.length - 1];
      }

      break;

    case 2013:
      // 模板13
      if (e.children.length == 0) {
        if (e.showpieceTotal > 0) {
          // console.log(e, '2013');

          return moduleType13.Subunit[1];
        } else {
          return moduleType13.Subunit[0];
        }
      } else if (e.children.length > 0) {
        return moduleType13.Subunit[2];
      }

      break;

    case 2001:
      // 模板15
      if (e.children.length == 0) {
        return moduleType15.Subunit[0];
      } else if (e.children.length == 1) {
        return moduleType15.Subunit[1];
      } else if (e.children.length == 2) {
        return moduleType15.Subunit[2];
      } else {
        return moduleType15.Subunit[3];
      }

      break;
    case 503306628902981:
      // 模板14
      // console.log(e, '503306628902981');

      if (e.children.length > 0) {
        return moduleType14.Subunit[2];
      } else if (e.showpieceTotal > 0) {
        return moduleType14.Subunit[1];
      } else {
        return moduleType14.Subunit[0];
      }

      break;
    case 505022027386949:
      let ChildUnitShow = getChildType(e.children);
      // 模板16

      if (e.children.length == 0 && e.showpieceTotal == 0) {
        // return  e.value ? SubunitList16List.Subunit[0] : [SubunitList16List.Subunit[0][3]];
        return SubunitList16List.Subunit[0];
      } else if (e.children.length == 0) {
        return SubunitList16List.Subunit[1];
      } else if (e.children.length > 0) {
        return SubunitList16List.Subunit[2];
      }

      break;
    case 507481625702469:
      // 模板18丹青妙手
      if (e.children.length == 0) {
        return moduleType18.Subunit[0];
      } else if (e.children.length > 0) {
        return moduleType18.Subunit[1];
      }

      break;
    case 1717:
      // 模板17
      if (e.children.length == 0 && e.showpieceTotal == 0) {
        return SubunitList17.Subunit[0];
      } else if (e.children.length == 0) {
        if (e.remarks?.length > 0 || e.value) {
          return SubunitList17.Subunit[1];
        } else return SubunitExhibits[0];
      } else if (e.children.length > 0) {
        return SubunitList17.Subunit[2];
      }
      break;
    case 529130430058565:
      // console.log('模版19切换逻辑');
      // let ChildUnitShow = getChildType(e.children);
      console.log(e);
      if (e.children.length == 0) {
        // 一级单元
        return SubunitList19List.Subunit[0];
      } else if (e.children.length > 0) {
        // 二级单元
        return SubunitList19List.Subunit[1];
      }

      break;
    default:
      if (e.children.length == 0) {
        return [];
      } else if (e.children.length > 2) {
        return moduleType.Subunit[6];
      } else {
        return moduleType.Subunit[e.children.length - 1];
      }

      break;
  }
};
export {
  getRandomModuleList,
  getStyleRandom,
  getEditRightTab,
  getGlobalColor,
  getUnitStyle,
  getGlobalTabList,
  getLogoTabList,
};
